<?php
	getHeader();
	
	if (isset($_SESSION['authPassed']))
	{
		if (isset($_POST['to']))
		{
			if ($_POST['from'] == $_SESSION['userName'])
			{
				$i = userProf::postMessage($_POST['from'], $_POST['to'], $_POST['title'], $_POST['content']);
				switch ($i)
				{
					case 0:
						echo "<span>发送成功</span>";
						break;
					case 1:
						echo "<span>查无此人</span>";
						break;
					case 2:
						echo "<span>标题或内容不符合规范</span>";
						break;
					case 3:
						echo "<span>不明原因发送失败</span>";
						break;
					default:
						echo "";
				}
			}
			else
			{
?>
				<span>输入无效</span>
<?php
			}
		}
		else
		{
?>
			<form action='?p=editMessage' method='post'>
				<span>发件人: <?php echo $_SESSION['userName']; ?><input type="hidden" name="from" value="<?php echo $_SESSION['userName']; ?>" /></span><br />
				<span>收件人: <input type="text" name="to" /></span><br />
				<span>标题: <input type="text" name="title" /></span><br />
				<span>内容: <textarea name="content" id="tinyInput"></textarea><?php getEditor(); ?></span><br />
				<span><input type="submit" value="发送" onclick="instance.post();" /></span>
			</form>
<?php
		}
	}
	else
	{
?>
		<span>你尚未登录, 不能进行此操作.</span>
<?php
	}
	getPanel();
	getFooter();
?>